﻿using Clippy.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;

namespace Clippy.Drivers
{
    public class ClippyPartDriver : ContentPartDriver<ClippyPart>
    {
        protected override DriverResult Display(ClippyPart part, string displayType, dynamic shapeHelper)
        {
            return ContentShape("Parts_Clippy",
                                () => shapeHelper.Parts_Clippy(Text: part.Text));
        }

        //GET
        protected override DriverResult Editor(ClippyPart part, dynamic shapeHelper)
        {
            return ContentShape("Parts_Clippy_Edit",
                                () => shapeHelper.EditorTemplate(TemplateName: "Parts/Clippy", Model: part));
        }
        //POST
        protected override DriverResult Editor(ClippyPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            updater.TryUpdateModel(part, Prefix, null, null);
            return Editor(part, shapeHelper);
        }
    }
}